package com.jishimed.pocus.androidbledemo;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by xiao on 2017/5/19.
 */

public class DevieceAdapter extends BaseAdapter{

    private List<BluetoothDevice> devices;
    private Context mContext;
    public DevieceAdapter(Context context,List<BluetoothDevice> devices){
        mContext = context;
        this.devices = devices;
    }

    public void update(List<BluetoothDevice> devices){
        this.devices = devices;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return null==devices?0:devices.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_devieces,null);
        }

        TextView tv_name = (TextView) convertView.findViewById(R.id.tv_name);
        TextView tv_address = (TextView) convertView.findViewById(R.id.tv_address);
        TextView tv_uuid = (TextView) convertView.findViewById(R.id.tv_uuid);
        BluetoothDevice bluetoothDevice = devices.get(position);
        tv_name.setText("name="+bluetoothDevice.getName());
        tv_address.setText("address="+bluetoothDevice.getAddress());
        tv_uuid.setText("uuid="+bluetoothDevice.getUuids());
        return convertView;
    }
}
